package com.bankcomm.ui.adapter;

import java.util.List;

import com.bankcomm.R;
import com.bankcomm.bean.Content;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SectionIndexer;
import android.widget.TextView;

public class NameAdapter extends BaseAdapter implements SectionIndexer {

	private List<Content> list = null;
	private Context mContext;

	public NameAdapter(Context mContext, List<Content> list) {
		this.mContext = mContext;
		this.list = list;

	}

	public int getCount() {
		return this.list.size();
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View view, ViewGroup arg2) {
		ViewHolder viewHolder = null;
		if (view == null) {
			viewHolder = new ViewHolder();
			view = LayoutInflater.from(mContext).inflate(R.layout.bcm_content_item_layout, null);
			viewHolder.tvName = (TextView) view.findViewById(R.id.cont_name);
			viewHolder.tvCardNum=(TextView) view.findViewById(R.id.cont_cardnum);
			viewHolder.tvCardType=(TextView) view.findViewById(R.id.cont_cardtype);
			viewHolder.tvTel=(TextView)view.findViewById(R.id.cont_tel);
			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) view.getTag();
		}
		
		viewHolder.tvName.setText(this.list.get(position).getName());
		viewHolder.tvCardNum.setText(this.list.get(position).getCardnum());
		viewHolder.tvCardType.setText(this.list.get(position).getCardtype());
		viewHolder.tvTel.setText(this.list.get(position).getTel());
		return view;

	}

	final static class ViewHolder {
		
		TextView tvName;
		TextView tvTel;
		TextView tvCardNum;
		TextView tvCardType;
	}

	public Object[] getSections() {
		return null;
	}

	public int getSectionForPosition(int position) {

		return 0;
	}

	public int getPositionForSection(int section) {
		Content mContent;
		String l;
//		if (section == '!') {
//			return 0;
//		} else {
			for (int i = 0; i < getCount(); i++) {
				mContent = (Content) list.get(i);
				l = mContent.getLetter();
				char firstChar = l.toUpperCase().charAt(0);
				if (firstChar == section) {
//					return i + 1;
					return i;
				}
			}
//		}
		mContent = null;
		l = null;
		return -1;
	}
}